package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.concurrent.TimeUnit;

import com.ruoyi.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisKeyValueTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TbCarMapper;
import com.ruoyi.system.domain.TbCar;
import com.ruoyi.system.service.ITbCarService;

/**
 * 车辆信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-12
 */
@Service
public class TbCarServiceImpl implements ITbCarService 
{
    @Autowired
    private TbCarMapper tbCarMapper;

    @Autowired
    private RedisService redisService;
    /**
     * 查询车辆信息
     * 
     * @param id 车辆信息主键
     * @return 车辆信息
     */
    @Override
    public TbCar selectTbCarById(Long id)
    {
        return tbCarMapper.selectTbCarById(id);
    }

    /**
     * 查询车辆信息列表
     * 
     * @param tbCar 车辆信息
     * @return 车辆信息
     */
    @Override
    public List<TbCar> selectTbCarList(TbCar tbCar)
    {
        List<TbCar> tbCars = tbCarMapper.selectTbCarList(tbCar);
        for (TbCar car : tbCars) {
            redisService.redisTemplate.opsForValue().set("品牌:", car.getVehicleBrand(),10, TimeUnit.MINUTES);
            redisService.redisTemplate.opsForValue().set("车型:", car.getVehicleModel(),10, TimeUnit.MINUTES);
            redisService.redisTemplate.opsForValue().set("车系:", car.getVehicleSeries(),10, TimeUnit.MINUTES);
        }

        return tbCars;
    }

    /**
     * 新增车辆信息
     * 
     * @param tbCar 车辆信息
     * @return 结果
     */
    @Override
    public int insertTbCar(TbCar tbCar)
    {
        return tbCarMapper.insertTbCar(tbCar);
    }

    /**
     * 修改车辆信息
     * 
     * @param tbCar 车辆信息
     * @return 结果
     */
    @Override
    public int updateTbCar(TbCar tbCar)
    {
        return tbCarMapper.updateTbCar(tbCar);
    }

    /**
     * 批量删除车辆信息
     * 
     * @param ids 需要删除的车辆信息主键
     * @return 结果
     */
    @Override
    public int deleteTbCarByIds(Long[] ids)
    {
        return tbCarMapper.deleteTbCarByIds(ids);
    }

    /**
     * 删除车辆信息信息
     * 
     * @param id 车辆信息主键
     * @return 结果
     */
    @Override
    public int deleteTbCarById(Long id)
    {
        return tbCarMapper.deleteTbCarById(id);
    }
}
